﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using nGSO.Performance;
using nGSO.Model;
using Be.Timvw.Framework.ComponentModel;
using System.Windows.Forms.DataVisualization.Charting;

namespace nGSO.UI
{
    public partial class AnalyticsWindow : Form
    {
        private AnalyticsManager _analyticsMngr = new AnalyticsManager();

        public AnalyticsWindow()
        {
            InitializeComponent();
        
            grvCases.DataSource = new SortableBindingList<AnalyticsOptions>(_analyticsMngr.GetAnalyticsParameterModel());
        }

        private void bgwRaportLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            ResultToChart charts = new ResultToChart();

            string selectedFunction = e.Argument.ToString();

            charts.OnRaportStateChanged += new LoadRaportStateHandler(charts_OnRaportStateChanged);

            charts.CompareGsoVerWithPopulation(selectedFunction, pnlOverallEffecinity);

            //charts.IterationGSOVerComparsion(selectedFunction, pnlIterationResults);
            
        }

        void charts_OnRaportStateChanged(object sender, LoadRaportEventArg e)
        {
            toolStripStatusLabel1.Text = e.StateDescription;
        }

        //private void btnClearDatabase_Click(object sender, EventArgs e)
        //{
        //    DialogResult res = MessageBox.Show("Clear ALL performance results?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

        //    if (res == System.Windows.Forms.DialogResult.OK)
        //    {

        //        PerfDatabase perfDb = new PerfDatabase();
        //        perfDb.ClearAllResults();
        //    }
        //}

        private void grvCases_SelectionChanged(object sender, EventArgs e)
        {
            btnStartRaport.Enabled = (grvCases.SelectedRows.Count == 1) ? true : false;    

        }

        private void btnStartRaport_Click(object sender, EventArgs e)
        {
            AnalyticsOptions selCase = grvCases.SelectedRows[0].DataBoundItem as AnalyticsOptions;

            using (ResultToChart charts = new ResultToChart())
            {
                charts.GenerateEffeciencyByCase(selCase, pnlOverallEffecinity);
            }
        }
        protected override void OnClosing(CancelEventArgs e)
        {
            _analyticsMngr.Dispose();
            base.OnClosing(e);
        }
    }

    
}